/*
 * @Description: 
 * @Author: hrc
 * @Date: 2024-10-09 14:29:40
 * @LastEditors: HuRrongChao
 * @LastEditTime: 2025-02-27 21:41:21
 */
import { defineConfig } from 'vite';
import path from 'path';
import vue from '@vitejs/plugin-vue'
import { domain } from './src/config.js'

export default defineConfig({
    plugins: [vue()],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src')
        }
    },
    server: {
        // 热更新
        hmr: true,
        // 设置主机地址
        host: '0.0.0.0',
        // 设置默认端口
        port: 8080,
        overlay: {
            warnings: true,
            errors: true
        },
        open: true,
        https: false,
        origin: 'http://localhost:8080',
        cors: true,
        proxy: {
            '/api': {
                target: domain,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ''),
                configure: (proxy, options) => {
                    proxy.on('proxyReq', function (proxyReq, req, res) {
                        proxyReq.setHeader('origin', domain)
                    })
                }
            }
        },
        headers: {
            'Access-Control-Allow-Origin': '*'
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: '@use "@/styles/skin.scss" as *;'
            }
        }
    }
});
